<template>
  <el-row
    type="flex"
    justify="sapce-between"
    align="center"
    style="width: 100%"
  >
    <!-- 左侧 -->
    <el-col>
      <span>{{ treeNode.name }}</span>
    </el-col>
    <!-- 右侧 -->
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ treeNode.manager }} </el-col>
        <el-col>
          <el-dropdown @command="operateDepts">
            <span>
              操作
              <i class="el-icon-arrow-down" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item command="edit">编辑部门</el-dropdown-item>
              <el-dropdown-item command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
import { delDepartments } from '@/api/departments'
export default {
  props: {
    treeNode: {
      type: Object,
      required: true
    }
  },
  methods: {
    operateDepts(type) {
      if (type === 'add') {
        this.$emit('addDepts', this.treeNode)
        // 添加操作
      } else if (type === 'edit') {
        // 编辑操作
        this.$emit('editDepts', this.treeNode)
      } else {
        // 删除操作
        this.$confirm('您确定要删除该部门么？')
          .then(() => {
            // 点击确认后进入
            return delDepartments(this.treeNode.id)
          })
          .then(() => {
            // 成功删除后进入到这里
            this.$emit('delDepts')
            this.$message('删除部门成功！！！')
          })
      }
    }
  }
}
</script>
<style scoped></style>
